#include "Minimax.h"

int Minimax::miniMax(int depth, BreakthroughGameState& s, std::vector< std::vector<char> >& grid)
{
	if ( s.getNumMoves() == 100 || depth <= 0)
	{
		return s.getEvaluation();
	}
	int bestValue = INT_MIN;
	std::vector<Move> moves = s.getLegalMoves(grid);
	for (int i = 0; i < moves.size(); ++i)
	{	
		//std::vector<Move> m;
		//m.push_back(moves[i]);
		std::cout << "Player " << s.getCurrentPlayer() << ' ';
		s.movePiece(grid, moves[i].fromX, moves[i].fromY, moves[i].toX, moves[i].toY);
		int value = -miniMax(depth-1, s, grid);
		//std::cout << value << '\n';
		s.retract(grid);
		//m.pop_back();
		//bestValue = std::max(value, bestValue);
		if (value > bestValue)
		{
			bestValue = value;
			m_bestMove = moves[i];
		}
	} 
	return bestValue;
}

Move& Minimax::getBestMove()
{
	return m_bestMove;
}